<template>
  <div style="background: #e8f1f8">
    <div class="det_tab">
      <div class="det_tab_item">
        <div style="margin-bottom: 10px">记录详情</div>
        <van-cell-group :border="border">
          <van-field
            label="检查人"
            class="input_text"
            :value="form.CreateChnName"
            readonly
          />
          <van-field
            label="检查日期"
            class="input_text"
            :value="form.CreateDate"
            readonly
          />
          <van-field
            label="最新状态"
            class="input_text"
            :value="form.StatusName"
            readonly
          />
          <van-field
            label="来源"
            class="input_text"
            :value="
              form.OriginType == 1
                ? '检查表检查'
                : form.StatusName == 2
                ? '依据检查'
                : '随手拍'
            "
            readonly
          />
          <van-field
            v-if="form.OriginType == 1"
            label="检查内容"
            class="input_text"
            rows="1"
            autosize
            type="textarea"
            :value="form.DetailItemName"
            readonly
          />
          <van-field
            label="检查结果"
            class="input_text"
            :value="
              form.CheckResult == 'N'
                ? '不符合'
                : form.CheckResult == 'NA'
                ? '不适用'
                : '符合'
            "
            readonly
          />

          <template v-if="form.CheckResult == 'N'">
            <van-field class="input_text" name="Attachs" label="隐患图片">
              <template #input>
                <div v-if="form.Attachs != null">
                  <template
                    v-for="(innerItem, inndeIndex) in form.Attachs.split(';')"
                  >
                    <van-image
                      style="margin-right: 10px"
                      :key="inndeIndex"
                      width="50"
                      height="50"
                      :src="baseUrl + innerItem"
                    />
                  </template>
                </div>
              </template>
            </van-field>
            <van-field
              label="隐患区域"
              class="input_text"
              :value="form.HiddenDangerArea"
              readonly
            />
            <van-field
              label="隐患描述"
              class="input_text"
              :value="form.HiddenDangerDesc"
              readonly
            />
            <van-field
              label="隐患分类"
              class="input_text"
              :value="form.LGDFullName"
              readonly
            />
            <van-field
                v-if="form.CheckResult == 'N'"
                label="隐患性质"
                class="input_text"
                :value="
                  form.HiddenDangerType == 2 ? '重大隐患' : '一般隐患'
                "
                readonly
              />
            <van-field
              v-if="form.GistSource"
              label="依据来源"
              class="input_text"
              :value="form.GistSource"
              rows="1"
              autosize
              type="textarea"
              readonly
            />
            <van-field
              label="整改建议"
              class="input_text"
              rows="1"
              autosize
              type="textarea"
              :value="form.CorrectiveAdvise || '无'"
              readonly
            />
            
            <van-field
              v-if="form.Status >= 30&&form.CorrectiveDeptName"
              label="整改部门"
              class="input_text"
              :value="form.CorrectiveDeptName"
              readonly
            />
            <van-field
              v-if="form.PlanCorrectiveDate"
              label="计划整改期限"
              class="input_text"
              :value="form.PlanCorrectiveDate"
              readonly
            />
            <van-field
              v-if="form.Status >= 40&&form.CorrectiveChnName"
              label="整改人"
              class="input_text"
              :value="form.CorrectiveChnName"
              readonly
            />
            <van-field
              v-if="form.Status >= 45 && form.Analysis"
              label="原因分析"
              class="input_text"
              :value="form.Analysis"
              readonly
            />
            <van-field
              v-if="form.Status >= 45"
              label="整改方式"
              class="input_text"
              :value="form.CorrectiveMethod == 1 ? '立即整改' : '限期整改'"
              readonly
            />
            <van-field
              v-if="form.Status >= 45 && form.CorrectiveMethod == 2"
              label="整改期限"
              class="input_text"
              :value="form.CorrectiveDate"
              readonly
            />
            <van-field
              v-if="form.Status >= 45 && form.CorrectiveMethod == 2"
              label="整改措施"
              class="input_text"
              :value="form.CorrectiveMeasure"
              rows="1"
              autosize
              type="textarea"
              readonly
            />
            <van-field
              v-if="form.Status >= 45 && form.Expenses"
              label="经费"
              class="input_text"
              :value="form.Expenses"
              readonly
            />

            <van-field
              v-if="form.Status >= 60"
              label="整改图片"
              class="input_text"
              :value="form.StatusName"
              readonly
            >
              <template #input>
                <div v-if="form.CorrectiveAttachs != null">
                  <template v-for="(innerItem, inndeIndex) in form.CorrectiveAttachs.split(';')" >
                    <van-image
                      style="margin-right: 10px"
                      :key="inndeIndex"
                      width="50"
                      height="50"
                      :src="baseUrl + innerItem"
                    />
                  </template>
                </div>
              </template>
            </van-field>
            <van-field
              v-if="form.Status >= 60"
              label="整改说明"
              class="input_text"
              :value="form.CorrectiveDesc"
              rows="1"
              autosize
              type="textarea"
              readonly
            />
          </template>
          <template v-else>
            <van-field
              class="input_text"
              label="备注"
              :value="form.Remarks"
              readonly
            />
          </template>
        </van-cell-group>
      </div>
      <div class="det_tab_item" style="margin-top: 10px">
        <div class="operate_det">
          <div style="margin-bottom: 10px">操作历史记录</div>
          <div class="operate_list">
            <van-row class="operate_row_first">
              <van-col span="4">序号</van-col>
              <van-col offset="1" span="10">操作</van-col>
            </van-row>
            <van-row
              v-for="(item, index) in form.LogList"
              :key="index"
              class="operate_row"
            >
              <van-col span="4">{{ index + 1 }}</van-col>
              <van-col offset="1" span="18"
                >{{ item.OperateLog }}
                <div v-if="item.Attachs">
                  <template
                    v-for="(innerItem, inndeIndex) in item.Attachs.split(';')"
                  >
                    <van-image
                      style="margin-right: 10px"
                      :key="inndeIndex"
                      width="50"
                      height="50"
                      :src="baseUrl + innerItem"
                    />
                  </template>
                </div>
              </van-col>
            </van-row>
            <!-- <van-row class="operate_row">
              <van-col span="4">1</van-col>
              <van-col offset="1" span="10">记得扣就防毒</van-col>
              <van-col offset="1" span="8">维保记录</van-col>r
            </van-row> -->
          </div>
        </div>
      </div>
      <div class="det_tab_item" style="margin-top: 10px">
        <div class="operate_det">
          <div style="margin-bottom: 10px">制定措施</div>
          <van-field class="input_text" name="radio" label="判定">
            <template #input>
              <van-radio-group v-model="radio" direction="horizontal">
                <van-radio icon-size="18px" name="1">制定措施</van-radio>
                <van-radio icon-size="18px" name="2">重新指派</van-radio>
              </van-radio-group>
            </template>
          </van-field>
          <div v-if="radio == 2">
            <van-field
              class="input_text"
              :value="editForm.CorrectiveChnName"
              required
              label="整改人"
              placeholder="请选择整改人"
              @click="showDeptUser()"
            >
              <template #right-icon><van-icon name="arrow" /></template>
            </van-field>
            <van-field
              v-model="editForm.Remarks"
              rows="2"
              autosize
              required
              label="说明"
              type="textarea"
              placeholder="请输入"
            />
          </div>
          <div v-else>
            <van-field class="input_text" name="radio" label="整改方式">
              <template #input v-if="radio != 2">
                <van-radio-group
                  v-model="editForm.CorrectiveMethod"
                  direction="horizontal"
                >
                  <van-radio icon-size="18px" name="1">立即整改</van-radio>
                  <van-radio icon-size="18px" name="2">限期整改</van-radio>
                </van-radio-group>
              </template>
            </van-field>
            <van-field
              v-if="editForm.CorrectiveMethod == '1'"
              class="input_text"
              name="uploader"
              required
              label="整改图片"
            >
              <template v-if="editForm.CorrectiveMethod == '1'" #input>
                <eagle-image-uploader
                  :images.sync="editForm.CorrectiveAttachs"
                ></eagle-image-uploader>
              </template>
            </van-field>

            <date-picker
              label="整改日期"
              labelWidth="80"
              v-if="editForm.CorrectiveMethod == '2'"
              required
              :date.sync="editForm.CorrectiveDate"
            ></date-picker>
            <van-field
              v-model="editForm.CorrectiveMeasure"
              v-if="editForm.CorrectiveMethod == '2'"
              rows="2"
              autosize
              label="整改措施"
              type="textarea"
              placeholder="请输入"
              required
              show-word-limit
            />
            <van-field
              v-model="editForm.CorrectiveDesc"
              v-if="editForm.CorrectiveMethod == '1'"
              rows="2"
              autosize
              required
              label="整改说明"
              type="textarea"
              placeholder="请输入"
            />
          </div>
        </div>
        <div style="margin: 16px">
          <van-button round block type="info" @click="submit">提交</van-button>
        </div>
      </div>
    </div>
    <user-choose-dialog
      isMulti="f"
      @callback="onUserCallback"
      :show.sync="showUserChooseDialog"
    ></user-choose-dialog>
  </div>
</template>

<script>
import { getDangerDetail } from "@/api/dangerCheckTaskDetail";
import {
  jgConfirmFormulate,
  jgFormulateAgainAssing,
} from "@/api/dangerCheckTaskDetailJG";
import { upload } from "@/api/common";
import { formatDate, getDate } from "@/utils/getDate";
import { deepClone } from "@/utils";
import UserChooseDialog from "@/views/components/user/userChooseDialog.vue";
export default {
  components: { UserChooseDialog },
  data() {
    return {
      baseUrl: process.env.VUE_APP_BASE_API,
      id: this.$route.query.id,
      border: false,
      active: "a",
      reason: false,
      expenses: false,
      showCalendar: false,
      CorrectiveUserName: "",
      CorrectiveChnName: "",
      form: {},
      imgs: [],
      editForm: {},
      remarks: "",
      fileList: [],
      radio: "1",
      showUserChooseDialog: false,
    };
  },
  created() {
    this.geDetail();
  },
  methods: {
    // 获取详情
    geDetail() {
      getDangerDetail({ id: this.id }).then((res) => {
        this.form = res.data;
        this.form.CorrectiveDesc=this.form.CorrectiveAdvise?this.form.CorrectiveAdvise:''
        this.editForm = deepClone(res.data);
        if (this.editForm.CorrectiveMeasure==null|| this.editForm.CorrectiveMeasure== "") {
          this.editForm.CorrectiveMeasure = this.editForm.CorrectiveAdvise;
        }
      });
    },

    submit() {
      // this.loading = true
      if (this.radio == 1) {
        let param = {
          ID: this.editForm.ID,
          CorrectiveMethod: this.editForm.CorrectiveMethod,
          CorrectiveDate: this.editForm.CorrectiveDate,
          CorrectiveMeasure: this.editForm.CorrectiveMeasure,
          CorrectiveAttachs: this.editForm.CorrectiveAttachs,
          CorrectiveDesc: this.editForm.CorrectiveDesc,
          CorrectiveUserName: this.editForm.CorrectiveUserName,
          CorrectiveChnName: this.editForm.CorrectiveChnName,
        };
        if (param.CorrectiveMethod == "1") {
          if (!param.CorrectiveAttachs) {
            this.$toast("请选择整改图片");
            return false;
          }
          if (!param.CorrectiveDesc) {
            this.$toast("请输入整改说明");
            return false;
          }
        } else {
          if (!param.CorrectiveDate) {
            this.$toast("请选择整改日期");
            return false;
          }
          if (!param.CorrectiveMeasure) {
            this.$toast("请输入整改措施");
            return false;
          }
        }
        jgConfirmFormulate(param)
          .then((res) => {
            this.$toast("保存成功");
            this.$router.go(-1);
          })
          .catch((err) => {
            console.log("err", err);
          });
      } else {
        let param = {
          ID: this.editForm.ID,
          CorrectiveUserName: this.editForm.CorrectiveUserName,
          CorrectiveChnName: this.editForm.CorrectiveChnName,
          Remarks: this.editForm.Remarks,
        };
          if (!param.Remarks) {
            this.$toast("请输入说明");
            return false;
          }
          if (!param.CorrectiveUserName) {
            this.$toast("请输入整改人");
            return false;
          }
        jgFormulateAgainAssing(param)
          .then((res) => {
            this.$toast("保存成功");
            this.geDetail()
            // this.$router.go(-1);
          })
          .catch((err) => {
            console.log("err", err);
          });
      }
    },
    showDeptUser() {
      this.showUserChooseDialog = true;
    },
    // 选择部门人回调
    onUserCallback(item) {
      this.editForm.CorrectiveUserName = item[0].code;
      this.editForm.CorrectiveChnName = item[0].name;
      this.showUserChooseDialog = false;
    },
  },
};
</script>

<style lang="less">
/*
        .main {
            height: 100vh;
        }
    */

.det_top_box {
  padding: 10px;
  background-color: #e8f1f8;
}

.detail_header {
  color: #ffffff;
  background: url("../../../assets/Images/AppIcon/image_riskunit_detail_bg.png");
  background-size: cover;
  padding: 10px;
  border-radius: 5px;
  /*background-color: #fff;*/

  .det_top {
    display: flex;
    justify-content: space-between;

    .dep_top_img {
      height: 20px;
      width: 20px;
      margin-right: 5px;
    }
  }

  .det_name {
    margin-top: 20px;
    text-align: center;
  }

  .det_location {
    text-align: center;
    margin-bottom: 20px;
  }
}

.det_tab {
  padding: 10px;
  .det_tab_item {
    padding: 10px 0;
    background-color: #fff;
    border-radius: 5px;
    margin-bottom: 10px;

    .det_tab_item_text {
      padding: 0 10px;
    }
  }
}
.text_box {
  padding: 10px;
  border-radius: 5px;
  /*background-color: #e8f1f8;*/
  margin-bottom: 10px;

  .text_top {
    margin-bottom: 10px;
    display: flex;
    justify-content: space-between;
    .top_link {
      color: #1989fa;
    }
  }

  .text_item {
    display: flex;
    justify-content: space-between;
    margin-left: 10px;

    .item_link {
      color: #1989fa;
    }
  }

  .text_img {
    display: flex;
    align-items: center;

    .img_item {
      width: 33.3%;
      text-align: center;

      img {
        height: 25px;
        width: 25px;
        margin-bottom: 10px;
      }
    }
  }

  .text_history {
    display: flex;
    vertical-align: middle;
    margin-bottom: 10px;
  }

  .text_member {
    color: #1989fa;
    margin-bottom: 10px;
  }

  .text_total_img {
    display: flex;
    align-items: center;

    .img_item {
      width: 33.3%;
      text-align: center;

      .img_item_top {
        display: flex;
        vertical-align: middle;
        margin-bottom: 10px;
      }
      img {
        height: 15px;
        width: 15px;
        margin-right: 5px;
      }
    }
  }
  .text_record_list {
    .list_row {
      display: flex;
      justify-content: space-between;
      margin-bottom: 10px;
      > div {
        width: 33.3%;
      }
      .row_center {
        text-align: center;
      }
      .row_right {
        text-align: right;
      }
    }
  }
}
.operate_det {
  background-color: #fff;
  padding: 10px;
  .operate_list {
    font-size: 12px;
    border: 1px solid #e8f1f8;
    .operate_row_first {
      padding: 10px;
      background-color: #e8f1f8;
      border-bottom: 1px solid #e8f1f8;
      margin-bottom: 10px;
    }
    .operate_row {
      padding: 10px;
      border-bottom: 1px solid #e8f1f8;
      /*margin-bottom: 10px;*/
    }
  }
}
</style>
